package com.example.studentcompetitionplatform.controller;

import com.example.studentcompetitionplatform.entity.Users;
import com.example.studentcompetitionplatform.service.IUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private IUserService userService;

    //登录
    @PostMapping("/login")
    public Users login(@RequestBody Users users){
        return userService.login(users);
    }
    //注册
    @PostMapping("/register")
    public Integer register(@RequestBody Users users){
        userService.register(users);
        return 1;
    }
    //删除
    @PostMapping("/del")
    public Integer delete(@RequestBody Users users){
        userService.delete(users);
        return 1;
    }
    //编辑
    @PostMapping("/edit")
    public Integer update(@RequestBody Users users){
        userService.update(users);
        return 1;
    }
    //分页数据查询
    @GetMapping("/page")
    public Map<String, Object> findPage(@RequestParam Integer pageNum,
                                        @RequestParam Integer pageSize,
                                        @RequestParam String username,
                                        @RequestParam String email,
                                        @RequestParam String phone) {

        return userService.page(pageNum,pageSize,username,email,phone);
    }
}
